package com.xuecheng.content.controller;

import com.xuecheng.commons.model.dto.BindTeachplanMediaDto;
import com.xuecheng.commons.model.dto.TeachplanDto;
import com.xuecheng.commons.model.vo.ResponseResult;
import com.xuecheng.content.service.TeachplanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程计划前端控制器
 * </p>
 *
 * @author itheima
 */
@Slf4j
@RestController
@RequestMapping("/teachplan")
public class TeachplanController {

    @Autowired
    private TeachplanService teachplanService;

    /**
     * 课程计划列表-树形结构
     * 请求路径：GET /{courseId}/tree-nodes
     * 路径参数：课程ID
     * 响应数据：ResponseResult<TeachplanVo>
     */
    @GetMapping("/{courseId}/tree-nodes")
    public ResponseResult treeNodes(@PathVariable("courseId") Long courseId) {
        return teachplanService.treeNodes(courseId);
    }

    //保存和更新
    @PostMapping
    public ResponseResult saveOrUpdate(@RequestBody TeachplanDto dto) {
        return teachplanService.saveOrUpdatePlan(dto);
    }

    //删除
    @DeleteMapping("{id}")
    public ResponseResult deleteTeachplan(@PathVariable("id") Long id) {
        return teachplanService.deleteTeachplan(id);
    }

    //课程计划绑定媒资
    @PostMapping("/media/association")
    public ResponseResult associateMedia(@RequestBody BindTeachplanMediaDto dto) {
        return teachplanService.associateMedia(dto);
    }
}
